package learnjava.basic.javaIO.FakeAIO;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 伪异步IO，每个连接不创建线程而是加入线程池的任务队列
 */
class Server{

    public static void main(String[] args) {
        ExecutorService pool = null;
        try {
            ServerSocket ss = new ServerSocket(9000);
            pool = Executors.newFixedThreadPool(2);
            Socket s;
            while ((s=ss.accept())!=null){
                System.out.println("收到一个客户端链接");
                pool.execute(new RunnableSocket(s));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            pool.shutdown();
        }
    }
}
